//
//  MenuTableViewCell.m
//  Foodie_Talk_ProjectA
//
//  Created by Ming on 15-6-9.
//  Copyright (c) 2015年 蓝欧科技. All rights reserved.
//

#import "MenuTableViewCell.h"
#import "BaseHeader.h"
#import "MenuSearchPage_Class.h"
#import "UIImageView+WebCache.h"

@implementation MenuTableViewCell
- (void)dealloc
{
    [_myImage release];
    [_nameLabel release];
    [_allClickLabel release];
    [_favoritesLabel release];
    [_burdensLabel release];
    [_menuClass release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.myImage = [[UIImageView alloc] init];
        self.myImage.layer.cornerRadius = 8;
        self.myImage.clipsToBounds = YES;
        [self.contentView addSubview:self.myImage];
        [_myImage release];
        
        self.nameLabel = [[UILabel alloc] init];
        self.nameLabel.font = [UIFont boldSystemFontOfSize:15];
        self.nameLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.allClickLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.allClickLabel];
        self.allClickLabel.textColor = [UIColor lightGrayColor];
        self.allClickLabel.font = [UIFont systemFontOfSize:11];
        [_allClickLabel release];
        
        self.favoritesLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.favoritesLabel];
        self.favoritesLabel.textColor = [UIColor lightGrayColor];
        self.favoritesLabel.font = [UIFont systemFontOfSize:11];
        [_favoritesLabel release];
        
        self.burdensLabel = [[UILabel alloc] init];
        self.burdensLabel.numberOfLines = 0;
        [self.burdensLabel sizeToFit];
        self.burdensLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.burdensLabel];
        [_burdensLabel release];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.myImage.frame = CGRectMake(tableViewWidth / 3 * 2 - 30, 5, tableViewWidth / 3 + 30, tableViewHeight - 10);
    self.nameLabel.frame = CGRectMake(- 30, 0, tableViewWidth / 3 * 2, tableViewHeight / 4);
    self.burdensLabel.frame = CGRectMake(0, tableViewHeight / 4, tableViewWidth / 3 * 2 - 30, tableViewHeight / 4 * 2);
    self.allClickLabel.frame = CGRectMake(- 30, tableViewHeight / 4 * 3, tableViewWidth / 3, tableViewHeight / 4);
    self.favoritesLabel.frame = CGRectMake(tableViewWidth / 3 - 50 , tableViewHeight / 4 * 3, tableViewWidth / 3, tableViewHeight / 4);
}

- (void)setMenuClass:(MenuSearchPage_Class *)menuClass
{
    if (_menuClass != menuClass) {
        [_menuClass release];
        _menuClass = [menuClass retain];
    }
    
    self.nameLabel.text = _menuClass.name;
    NSURL *url = [NSURL URLWithString: _menuClass.img];
    [self.myImage setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    //[self.myImageView setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"placeholder"]];

    self.burdensLabel.text = _menuClass.burdens;
    self.allClickLabel.text = [NSString stringWithFormat:@"%@/浏览", _menuClass.allClick];
    self.allClickLabel.textAlignment = NSTextAlignmentRight;
    self.favoritesLabel.text =[NSString stringWithFormat:@"%@/收藏", _menuClass.favorites];
    self.favoritesLabel.textAlignment = NSTextAlignmentRight;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
